﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Webdiyer.WebControls.Mvc;

namespace MvcWeb.Controllers
{
    public class ManagerController :BaseController
    {
        //
        // GET: /Manager/
        public ActionResult Index(int pageindex = 1, int pageSize = 20)
        {
            var iquery = db.AssetManager.AsQueryable();

            iquery = iquery.OrderBy(m => m.AssetID);

            var list = iquery.ToPagedList(pageindex, pageSize);


            var dict = db.AssetCategory.ToDictionary(a => a.CategoryID, b => b.CategoryName);
            dict.Add(-1, "");
            ViewData["categoryCID"] = dict;

            ViewData["BrandSupplyType"] = new SelectList(MvcWeb.EAMEnum.EAMEnumExt.ToListItem<MvcWeb.EAMEnum.SupplyBrand>(), "value", "text");

            var brandDict = db.AssetBrandSupply.Where(m => (int)m.BrandSupplyType == (int)MvcWeb.EAMEnum.SupplyBrand.品牌商)
                .ToDictionary(a => a.BrandSupplyID, b => b.BrandSupplyName);
            brandDict.Add(-1, "");
            ViewData["brandDict"] = brandDict;

            var supplyDict = db.AssetBrandSupply.Where(m => (int)m.BrandSupplyType == (int)MvcWeb.EAMEnum.SupplyBrand.供应商)
                .ToDictionary(a => a.BrandSupplyID, b => b.BrandSupplyName);
            supplyDict.Add(-1, "");
            ViewData["supplyDict"] = supplyDict;

            var brandInfoDict = db.AssetBrandSupply.Where(m => (int)m.BrandSupplyType == (int)MvcWeb.EAMEnum.SupplyBrand.供应商).ToList();
            var brandInfoDictL = brandInfoDict.ToDictionary(a => a.BrandSupplyID, b => b.BrandSupplyName);
            brandInfoDictL.Add(-1, "");
            ViewData["brandInfoDict"] = brandInfoDictL;


            var configType = db.AssetConfigOther.ToList();

            var AssetStatus = configType.Where(m => m.AssetConfigType == (int)MvcWeb.EAMEnum.ConfigType.资产状态)
                .ToDictionary(a => a.AssetConfigID, b => b.AssetConfigName);
            AssetStatus.Add(-1, "");
            ViewData["statusDict"] = AssetStatus;


            var users = db.aspnet_Users.ToList().ToDictionary(a => a.UserId, b => b.UserName);
            users.Add(new Guid(), "");
            ViewData["AssetCustodyMemberIDDict"] = users;

            var userDepts = db.User_Depts.ToList().ToDictionary(a => a.Id, b => b.Name);
            userDepts.Add(-1, "");
            ViewData["AssetDepartIDDict"] = userDepts;

            return View(list); 
        }

        public ActionResult EditFromCategory(MvcWeb.ViewModels.Manager.ManagerModel viewModel)
        {
            viewModel = new ViewModels.Manager.ManagerModel();
            viewModel.assetManagerModel = new EAM.Model.AssetManager();
            var categoryType = db.AssetCategory.Where(m => m.CategoryParentID == -1 && m.CategoryIsShow == true)
                .ToDictionary(a => a.CategoryID, b => b.CategoryName);

            ViewData["categoryTypeList"] = new SelectList(categoryType, "key", "value");

            return View(viewModel);
        }

        [HttpPost]
        [ActionName("EditFromCategory")]
        public ActionResult EditFromCategory2(MvcWeb.ViewModels.Manager.ManagerModel viewModel)
        {
            return RedirectToAction("Edit", new { id = -1, cid = (int)viewModel.assetManagerModel.AssetCID, count = viewModel.assetManagerCount });
        }

        public ActionResult Edit( int id = -1 ,int cid=-1, int count=1  )
        {
            MvcWeb.ViewModels.Manager.ManagerModel model = new ViewModels.Manager.ManagerModel();

            model.assetManagerModel = null;

            if (id == -1)
            {
                model.assetManagerModel = new EAM.Model.AssetManager();
                model.assetManagerModel.AssetCID = cid;

                model.assetManagerConfigModels = new List<EAM.Model.AssetManagerConfig>();

                model.assetManagerCount = count;
            }
            else
            {
                model.assetManagerModel =  db.AssetManager.Find(id);
                model.assetManagerConfigModels = db.AssetManagerConfig.Where(m => m.AssetID == id).ToList();
                model.assetManagerCount = count;
            }
            

            var categoryType = db.AssetCategory.Where(m => m.CategoryParentID == -1 && m.CategoryIsShow == true)
                .ToDictionary(a => a.CategoryID, b => b.CategoryName);
            ViewData["categoryTypeList"] = categoryType;

            var childCategoryType = db.AssetCategory.Where(m => m.CategoryParentID == cid && m.CategoryIsShow == true)
                .ToDictionary(a => a.CategoryID, b => b.CategoryName);//子类型

            var brandSupply = db.AssetBrandSupply.ToList();//供应商 品牌商
            var supplyList = brandSupply.Where(m => m.BrandSupplyType == (int)MvcWeb.EAMEnum.SupplyBrand.供应商)
                .ToDictionary(a=> a.BrandSupplyID , b=> b.BrandSupplyName);
            var brandList = brandSupply.Where(m => m.BrandSupplyType == (int)MvcWeb.EAMEnum.SupplyBrand.品牌商)
                .ToDictionary(a => a.BrandSupplyID, b => b.BrandSupplyName);
            ViewData["brandList"] = brandList;
            ViewData["supplyList"] = supplyList;
            
            var userDepts = db.User_Depts.ToList().ToDictionary(a=>a.Id , b=>b.Name);//部门
            ViewData["AssetDepartIDList"] = userDepts;

            var users = db.aspnet_Users.ToList().ToDictionary(a=>a.UserId,b=>b.UserName);//用户信息
            ViewData["AssetCustodyMemberIDList"] = users;
            ViewData["AssetUsedMemberIDList"] = users;
            ViewData["AssetPurchaseIDList"] = users;

            var configType = db.AssetConfigOther.ToList();//配置信息
            var manLevel = configType.Where(m => m.AssetConfigType == (int)MvcWeb.EAMEnum.ConfigType.资产等级)
                .ToDictionary(a => a.AssetConfigID, b => b.AssetConfigName);
            ViewData["AssetLevelList"] = manLevel;

            var purchaseCostFromLevel = configType.Where(m => m.AssetConfigType == (int)MvcWeb.EAMEnum.ConfigType.资金来源)
                .ToDictionary(a => a.AssetConfigID, b => b.AssetConfigName);
            ViewData["AssetPurchaseCostFromList"] = purchaseCostFromLevel;


            var fromLevel = configType.Where(m => m.AssetConfigType == (int)MvcWeb.EAMEnum.ConfigType.资产增加来源)
                .ToDictionary(a => a.AssetConfigID, b => b.AssetConfigName);
            ViewData["AssetFromList"] = fromLevel;


            var AssetOut = configType.Where(m => m.AssetConfigType == (int)MvcWeb.EAMEnum.ConfigType.资产减少去处)
                .ToDictionary(a => a.AssetConfigID, b => b.AssetConfigName);
            ViewData["AssetOutList"] = AssetOut;

            var AssetStatus = configType.Where(m => m.AssetConfigType == (int)MvcWeb.EAMEnum.ConfigType.资产状态)
                .ToDictionary(a => a.AssetConfigID, b => b.AssetConfigName);
            ViewData["AssetStatusList"] = AssetStatus;

            return View(model);
        }

        [HttpPost]
        public ActionResult Edit(MvcWeb.ViewModels.Manager.ManagerModel viewModel, int id = -1)
        {
            var user = System.Web.Security.Membership.GetUser();
            var guid = (Guid)user.ProviderUserKey;

            //品牌商
            int brandId = 0;
            if ((viewModel.assetManagerModel.AssetBrand ?? 0) == 0)
            {
                if (!string.IsNullOrWhiteSpace(viewModel.BrandName))
                {
                    var brandModel = new EAM.Model.AssetBrandSupply()
                    {
                        BrandSupplyName = viewModel.BrandName,
                        BrandSupplyType = (int)MvcWeb.EAMEnum.SupplyBrand.品牌商
                    };

                    db.AssetBrandSupply.Add(brandModel);
                    db.SaveChanges();
                    brandId = brandModel.BrandSupplyID;
                }
            }

            //供应商
            int supplyId = 0;
            if ((viewModel.assetManagerModel.AssetSupply ?? 0) == 0)
            {
                if (!string.IsNullOrWhiteSpace(viewModel.Supplier))
                {
                    var supplyModel = new EAM.Model.AssetBrandSupply()
                    {
                        BrandSupplyName = viewModel.Supplier,
                        BrandSupplyType = (int)MvcWeb.EAMEnum.SupplyBrand.供应商
                    };

                    db.AssetBrandSupply.Add(supplyModel);
                    db.SaveChanges();
                    supplyId = supplyModel.BrandSupplyID;
                }
            }

            if (id == -1)
            {
                EAM.Model.AssetCategory categoryModel = db.AssetCategory.Where(m => m.CategoryID == viewModel.assetManagerModel.AssetCID).FirstOrDefault();
                db.AssetCategory.Attach(categoryModel);

                for (int count = 0; count < viewModel.assetManagerCount; count++)
                {
                    categoryModel.CategoryNumCount = categoryModel.CategoryNumCount == null ? 0 : categoryModel.CategoryNumCount + 1;
                    categoryModel.CategoryShowNumCount = categoryModel.CategoryShowNumCount == null ? 0 : categoryModel.CategoryShowNumCount + 1;

                    string categoryLength = categoryModel.CategoryNumCount.ToString();
                    for (int i = categoryLength.Length; i < 12; i++)//填充标签内容为12长度
                    {
                        categoryLength = "0" + categoryLength;
                    }
                    string label = categoryModel.CategoryLabel + "_" + categoryLength;

                    string assetName = viewModel.assetManagerModel.AssetName;
                    if (viewModel.assetManagerCount > 1)//如果是批量增加的,就在后面添加这对应的数字
                        assetName = assetName + "_" + count.ToString();

                    //添加资产信息
                    EAM.Model.AssetManager model = new EAM.Model.AssetManager()
                    {
                        AssetName = assetName ,
                        AssetCID = viewModel.assetManagerModel.AssetCID,
                        AssetBrand = viewModel.assetManagerModel.AssetBrand ?? brandId,
                        AssetBarcode = viewModel.assetManagerModel.AssetBarcode,

                        AssetLabel = label, // viewModel.assetManagerModel.AssetLabel,

                        AssetStatus = viewModel.assetManagerModel.AssetStatus,
                        AssetSupply = viewModel.assetManagerModel.AssetSupply ?? supplyId,
                        AssetContractID = viewModel.assetManagerModel.AssetContractID,
                        AssetPurchaseID = viewModel.assetManagerModel.AssetPurchaseID,
                        AssetPurchaseName = viewModel.assetManagerModel.AssetPurchaseName,
                        AssetPurchaseCost = viewModel.assetManagerModel.AssetPurchaseCost,
                        AssetPurchaseCostFrom = viewModel.assetManagerModel.AssetPurchaseCostFrom,
                        AssetPurchaseTime = viewModel.assetManagerModel.AssetPurchaseTime,
                        AssetFrom = viewModel.assetManagerModel.AssetFrom,
                        AssetOut = viewModel.assetManagerModel.AssetOut,
                        AssetOutManu = viewModel.assetManagerModel.AssetOutManu,

                        AssetCustodyAddress = viewModel.assetManagerModel.AssetCustodyAddress,
                        AssetCustodyMemberID = viewModel.assetManagerModel.AssetCustodyMemberID,
                        AssetCustodyMemberName = viewModel.assetManagerModel.AssetCustodyMemberName,

                        AssetUsedMemberID = viewModel.assetManagerModel.AssetUsedMemberID,
                        AssetUsedMemberName = viewModel.assetManagerModel.AssetUsedMemberName,
                        AssetUsedAddress = viewModel.assetManagerModel.AssetUsedAddress,

                        AssetUsedYear = viewModel.assetManagerModel.AssetUsedYear,

                        AssetDepriciationRate = viewModel.assetManagerModel.AssetDepriciationRate,
                        AssetDepartID = viewModel.assetManagerModel.AssetDepartID,
                        AssetDepartName = viewModel.assetManagerModel.AssetDepartName,
                        AssetDescript = viewModel.assetManagerModel.AssetDescript,

                        AssetLevel = viewModel.assetManagerModel.AssetLevel,
                        AssetBuyCode = viewModel.assetManagerModel.AssetBuyCode,
                        AssetBuysssInvoiceNumber = viewModel.assetManagerModel.AssetBuysssInvoiceNumber,
                        AssetBuyTime = viewModel.assetManagerModel.AssetBuyTime,
                        AssetSpecModel = viewModel.assetManagerModel.AssetSpecModel,
                        AssetInventoryMemberIDs = viewModel.assetManagerModel.AssetInventoryMemberIDs,

                        AssetInventoryExists = viewModel.assetManagerModel.AssetInventoryExists,
                        AssetInventoryMemberName = viewModel.assetManagerModel.AssetInventoryMemberName,
                        AssetInventoryTime = viewModel.assetManagerModel.AssetInventoryTime,
                        AssetMaintenanCycle = viewModel.assetManagerModel.AssetMaintenanCycle,
                        AssetLastUpdateMember = viewModel.assetManagerModel.AssetLastUpdateMember,
                        AssetLastUpdateTime = viewModel.assetManagerModel.AssetLastUpdateTime,
                        AssetPictures = viewModel.assetManagerModel.AssetPictures,
                        AssetRegisterMember = viewModel.assetManagerModel.AssetRegisterMember,
                        AssetRegisterTime = viewModel.assetManagerModel.AssetRegisterTime,

                        AssetWarrant = viewModel.assetManagerModel.AssetWarrant,
                        AssetWarrantLastTime = viewModel.assetManagerModel.AssetWarrantLastTime
                    };
                    db.AssetManager.Add(model);
                    db.SaveChanges();

                    //添加关联信息
                    EAM.Model.AssetManagerConfig newModel = null;
                    int cid = viewModel.assetManagerModel.AssetCID;
                    string val = null;
                    if (cid > 0)
                    {
                        var configList = db.AssetCategory.Where(m => m.CategoryParentID == cid).ToList();
                        foreach (var m in configList)
                        {
                            val = Request.Form[m.CategoryLabel + m.CategoryParentID];
                            newModel = new EAM.Model.AssetManagerConfig()
                            {
                                AssetID = model.AssetID,

                                AssetManConfigTypeID = m.CategoryID,
                                AssetManConfigTypeName = m.CategoryName,
                                AssetManConfigValue = val,
                                LastUpdateMember = guid,
                                LastUpdateTime = DateTime.Now
                            };
                            db.AssetManagerConfig.Add(newModel);
                        }
                    }

                }
            }
            else
            {
                var model = db.AssetManager.Find(id);
                db.AssetManager.Attach(model);

                model.AssetName = viewModel.assetManagerModel.AssetName;
                model.AssetCID = viewModel.assetManagerModel.AssetCID;
                model.AssetBrand = viewModel.assetManagerModel.AssetBrand ?? brandId;
                model.AssetBarcode = viewModel.assetManagerModel.AssetBarcode;
                model.AssetLabel = viewModel.assetManagerModel.AssetLabel;
                model.AssetStatus = viewModel.assetManagerModel.AssetStatus;
                model.AssetSupply = viewModel.assetManagerModel.AssetSupply ?? supplyId;
                model.AssetContractID = viewModel.assetManagerModel.AssetContractID;
                model.AssetPurchaseID = viewModel.assetManagerModel.AssetPurchaseID;
                model.AssetPurchaseName = viewModel.assetManagerModel.AssetPurchaseName;
                model.AssetPurchaseCost = viewModel.assetManagerModel.AssetPurchaseCost;
                model.AssetPurchaseCostFrom = viewModel.assetManagerModel.AssetPurchaseCostFrom;
                model.AssetPurchaseTime = viewModel.assetManagerModel.AssetPurchaseTime;
                model.AssetFrom = viewModel.assetManagerModel.AssetFrom;
                model.AssetOut = viewModel.assetManagerModel.AssetOut;
                model.AssetOutManu = viewModel.assetManagerModel.AssetOutManu;

                model.AssetCustodyAddress = viewModel.assetManagerModel.AssetCustodyAddress;
                model.AssetCustodyMemberID = viewModel.assetManagerModel.AssetCustodyMemberID;
                model.AssetCustodyMemberName = viewModel.assetManagerModel.AssetCustodyMemberName;

                model.AssetUsedMemberID = viewModel.assetManagerModel.AssetUsedMemberID;
                model.AssetUsedMemberName = viewModel.assetManagerModel.AssetUsedMemberName;
                model.AssetUsedAddress = viewModel.assetManagerModel.AssetUsedAddress;

                model.AssetUsedYear = viewModel.assetManagerModel.AssetUsedYear;

                model.AssetDepriciationRate = viewModel.assetManagerModel.AssetDepriciationRate;
                model.AssetDepartID = viewModel.assetManagerModel.AssetDepartID;
                model.AssetDepartName = viewModel.assetManagerModel.AssetDepartName;
                model.AssetDescript = viewModel.assetManagerModel.AssetDescript;

                model.AssetLevel = viewModel.assetManagerModel.AssetLevel;
                model.AssetBuyCode = viewModel.assetManagerModel.AssetBuyCode;
                model.AssetBuysssInvoiceNumber = viewModel.assetManagerModel.AssetBuysssInvoiceNumber;
                model.AssetBuyTime = viewModel.assetManagerModel.AssetBuyTime;
                model.AssetSpecModel = viewModel.assetManagerModel.AssetSpecModel;
                model.AssetInventoryMemberIDs = viewModel.assetManagerModel.AssetInventoryMemberIDs;

                model.AssetInventoryExists = viewModel.assetManagerModel.AssetInventoryExists;
                model.AssetInventoryMemberName = viewModel.assetManagerModel.AssetInventoryMemberName;
                model.AssetInventoryTime = viewModel.assetManagerModel.AssetInventoryTime;
                model.AssetMaintenanCycle = viewModel.assetManagerModel.AssetMaintenanCycle;
                model.AssetLastUpdateMember = viewModel.assetManagerModel.AssetLastUpdateMember;
                model.AssetLastUpdateTime = viewModel.assetManagerModel.AssetLastUpdateTime;
                model.AssetPictures = viewModel.assetManagerModel.AssetPictures;
                model.AssetRegisterMember = viewModel.assetManagerModel.AssetRegisterMember;
                model.AssetRegisterTime = viewModel.assetManagerModel.AssetRegisterTime;

                model.AssetWarrant = viewModel.assetManagerModel.AssetWarrant;
                model.AssetWarrantLastTime = viewModel.assetManagerModel.AssetWarrantLastTime;

                var manConfigModel = db.AssetManagerConfig.Where(m => m.AssetID == id);
                var categoryList = db.AssetCategory.Where(m => m.CategoryParentID == viewModel.assetManagerModel.AssetCID).ToList();
                foreach (var m in manConfigModel)
                {
                    db.AssetManagerConfig.Attach(m);
                    var cModel = categoryList.FirstOrDefault(a => a.CategoryID == m.AssetManConfigTypeID);
                    m.AssetManConfigValue = Request.Form[cModel.CategoryLabel + cModel.CategoryParentID];
                    m.LastUpdateMember = guid;
                    m.LastUpdateTime = DateTime.Now;
                }

            }

            db.SaveChanges();
            return RedirectToAction("Index");
        }

        
        public ActionResult DeleteChoose()
        {
            string ids = Request.Form["ids"];
            if (!string.IsNullOrWhiteSpace(ids))
            {
                string[] arr = ids.Split(',');
                foreach (var m in arr)
                {
                    var model = db.AssetManager.Find(int.Parse(m));

                    EAM.Model.AssetCategory categoryModel = db.AssetCategory.Where(a => a.CategoryID == model.AssetCID).FirstOrDefault();
                    db.AssetCategory.Attach(categoryModel);
                    categoryModel.CategoryShowNumCount = categoryModel.CategoryShowNumCount - 1;

                    db.AssetManager.Remove(model);
                }
                db.SaveChanges();
            }
            return Json(true);
        }

        
        public ActionResult del(int id = -1)
        {
            
            string ids = id==-1 ? Request.Form["ids"] : id.ToString();
            if (!string.IsNullOrWhiteSpace(ids))
            {
                string[] arr = ids.Split(',');
                foreach (var m in arr)
                {
                    var model = db.AssetManager.Find(int.Parse(m));

                    EAM.Model.AssetCategory categoryModel = db.AssetCategory.Where(a => a.CategoryID == model.AssetCID).FirstOrDefault();
                    db.AssetCategory.Attach(categoryModel);
                    categoryModel.CategoryShowNumCount = categoryModel.CategoryShowNumCount - 1;

                    db.AssetManager.Remove(model);
                }
                db.SaveChanges();
            }
            return RedirectToAction("Index");// Json(true);
        }

        public ActionResult AssetCollect(int pageindex = 1 ,int pageSize =20)
        {
            var cartList = db.AssetCategory.Where(m => m.CategoryIsShow == true).ToList();
            var list = db.AssetManager.ToList();

            List<MvcWeb.ViewModels.Manager.AssetCollectModel> collectlList = new List<MvcWeb.ViewModels.Manager.AssetCollectModel>();
            foreach (EAM.Model.AssetCategory cateModel in cartList)
            {
                //var assetAList = list.Where(m => m.AssetCID == cateModel.CategoryID).ToList();

                MvcWeb.ViewModels.Manager.AssetCollectModel collectModel = new ViewModels.Manager.AssetCollectModel();
                collectModel.CategoryID = cateModel.CategoryID;
                collectModel.CategoryName = cateModel.CategoryName;
                collectModel.CategoryStoredCount = list.Where(m => m.AssetCID == cateModel.CategoryID && m.AssetStatus == (int)MvcWeb.EAMEnum.AssetStatusEnum.库存).Count();

                collectModel.CategoryUsedCount = list.Where(m => m.AssetCID == cateModel.CategoryID && m.AssetStatus == (int)MvcWeb.EAMEnum.AssetStatusEnum.使用中).Count();

                collectModel.CategoryWorthlessCount = list.Where(m => m.AssetCID == cateModel.CategoryID && m.AssetStatus == (int)MvcWeb.EAMEnum.AssetStatusEnum.报废).Count();

                collectModel.CategoryAllCount = list.Count();

                collectlList.Add(collectModel);
            }

            var retList = collectlList; //.(pageindex, pageSize,m=>m.CategoryID>0);

            return View(retList);
        }

        public ActionResult AssetCollectDetail(int assetCID, int assetStatus , int pageindex = 1, int pageSize = 20)
        {
            var iquery = db.AssetManager.AsQueryable();

            iquery = iquery.Where(m => m.AssetCID == assetCID && m.AssetStatus == assetStatus );

            iquery = iquery.OrderBy(m => m.AssetID);

            var list = iquery.ToPagedList(pageindex, pageSize);


            var dict = db.AssetCategory.ToDictionary(a => a.CategoryID, b => b.CategoryName);
            dict.Add(-1, "");
            ViewData["categoryCID"] = dict;

            ViewData["BrandSupplyType"] = new SelectList(MvcWeb.EAMEnum.EAMEnumExt.ToListItem<MvcWeb.EAMEnum.SupplyBrand>(), "value", "text");


            var brandDict = db.AssetBrandSupply.Where(m => (int)m.BrandSupplyType == (int)MvcWeb.EAMEnum.SupplyBrand.品牌商)
                .ToDictionary(a => a.BrandSupplyID, b => b.BrandSupplyName);
            brandDict.Add(-1, "");
            ViewData["brandDict"] = brandDict;

            var supplyDict = db.AssetBrandSupply.Where(m => (int)m.BrandSupplyType == (int)MvcWeb.EAMEnum.SupplyBrand.供应商)
                .ToDictionary(a => a.BrandSupplyID, b => b.BrandSupplyName);
            supplyDict.Add(-1, "");
            ViewData["supplyDict"] = supplyDict;

            var brandInfoDict = db.AssetBrandSupply.Where(m => (int)m.BrandSupplyType == (int)MvcWeb.EAMEnum.SupplyBrand.供应商).ToList();
            var brandInfoDictL = brandInfoDict.ToDictionary(a => a.BrandSupplyID, b => b.BrandSupplyName);
            brandInfoDictL.Add(-1, "");
            ViewData["brandInfoDict"] = brandInfoDictL;


            var configType = db.AssetConfigOther.ToList();

            var AssetStatus = configType.Where(m => m.AssetConfigType == (int)MvcWeb.EAMEnum.ConfigType.资产状态)
                .ToDictionary(a => a.AssetConfigID, b => b.AssetConfigName);
            AssetStatus.Add(-1, "");
            ViewData["statusDict"] = AssetStatus;


            var users = db.aspnet_Users.ToList().ToDictionary(a => a.UserId, b => b.UserName);
            users.Add(new Guid(), "");
            ViewData["AssetCustodyMemberIDDict"] = users;

            var userDepts = db.User_Depts.ToList().ToDictionary(a => a.Id, b => b.Name);
            userDepts.Add(-1, "");
            ViewData["AssetDepartIDDict"] = userDepts;

            return View(list);
        }
    }
}
